package com.yyb.service.impl;

import com.github.pagehelper.Page;
import com.yyb.common.PageInfo;
import com.yyb.domain.SysNotice;
import com.yyb.dto.SysNoticeAddDTO;
import com.yyb.dto.SysNoticeQueryDTO;
import com.yyb.dto.SysNoticeUpdateDTO;
import com.yyb.mapper.SysNoticeMapper;
import com.yyb.service.SysNoticeService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 描述: [通知公告业务层]
 * 
 * 
 */
@Service
public class SysNoticeServiceImpl extends BaseServiceImpl<SysNotice> implements SysNoticeService {

    @Resource
    private SysNoticeMapper sysNoticeMapper;

    /**
     * 分页查询通知公告
     *
     * @param pageInfo
     * @return
     */
    @Override
    public PageInfo<SysNotice, SysNoticeQueryDTO> getByPage(PageInfo<SysNotice, SysNoticeQueryDTO> pageInfo) {
        Page<SysNotice> sysNoticePage = this.startPage(pageInfo.getPageNumber(), pageInfo.getPageSize());
        List<SysNotice> sysNoticeList=this.sysNoticeMapper.queryAllNotice(pageInfo.getParams());
        pageInfo.setTotalPage(sysNoticePage.getPages());
        pageInfo.setTotalCount(sysNoticePage.getTotal());
        pageInfo.setList(sysNoticeList);
        return pageInfo;
    }

    /**
     * 添加通知公告
     *
     * @param sysNoticeAddDTO
     * @return
     */
    @Override
    public int insert(SysNoticeAddDTO sysNoticeAddDTO) {
        SysNotice sysNotice=new SysNotice();
        BeanUtils.copyProperties(sysNoticeAddDTO,sysNotice);
        //填充其它属性
        sysNotice.setCreateBy(getUsername());
        Date time = new Date();
        sysNotice.setCreateTime(time);
        sysNotice.setUpdateTime(time);
        return this.sysNoticeMapper.insertSelective(sysNotice);
    }

    /**
     * 修改通知公告
     *
     * @param sysNoticeUpdateDTO
     * @return
     */
    @Override
    public int updateByPrimaryKey(SysNoticeUpdateDTO sysNoticeUpdateDTO) {
        SysNotice sysNotice=new SysNotice();
        BeanUtils.copyProperties(sysNoticeUpdateDTO,sysNotice);
        //填充其它属性
        sysNotice.setUpdateBy(getUsername());
        Date time = new Date();
        sysNotice.setUpdateTime(time);
        return this.sysNoticeMapper.updateByPrimaryKeySelective(sysNotice);
    }

    /**
     * 根据ID查询通知公告
     *
     * @param noticeId
     * @return
     */
    @Override
    public SysNotice selectByPrimaryKey(Long noticeId) {
        return this.sysNoticeMapper.selectByPrimaryKey(noticeId);
    }

    /**
     * 删除通知公告
     *
     * @param noticeId
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Long noticeId) {
        return this.sysNoticeMapper.deleteByPrimaryKey(noticeId);
    }
}
